package com.cn.hotel.service.impl;

import com.cn.hotel.dao.IRoomDao;
import com.cn.hotel.dao.Impl.RoomImpl;
import com.cn.hotel.model.HomeThreeShowModel;
import com.cn.hotel.model.NavModel;
import com.cn.hotel.model.RoomModel;
import com.cn.hotel.service.IRoomService;
import redis.clients.jedis.Jedis;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RoomServiceImpl implements IRoomService {
    /**
     * 添加
     *
     * @param roomModel
     * @return
     */
    @Override
    public int add(RoomModel roomModel) {
        IRoomDao iRoomDao = new RoomImpl();
        int result = iRoomDao.add(roomModel);
        return result;
    }

    /**
     * 查询
     *
     * @param roomModel
     * @return
     */
    @Override
    public List<RoomModel> findAll(RoomModel roomModel) {
        IRoomDao iRoomDao = new RoomImpl();
        List<RoomModel> list = iRoomDao.findAll(roomModel);
        return list;
    }

    /**
     * 得到总条树
     *
     * @param roomModel
     * @return
     */
    @Override
    public int getCount(RoomModel roomModel) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.getCount(roomModel);
    }

    /**
     * 通过房间编号查询信息  然后给编辑页面赋值所点击的信息
     *
     * @param aa
     * @return
     */
    @Override
    public RoomModel findByRoomId(Integer aa) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.findByRoomId(aa);
    }

    /**
     * 根据id删除
     *
     * @param temp
     * @return
     */
    @Override
    public int delete(Integer temp) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.delete(temp);
    }

    /**
     * 编辑提交数据
     *
     * @param roomModel
     * @return
     */
    @Override
    public int edit(RoomModel roomModel) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.edit(roomModel);
    }

    @Override
    public List<HomeThreeShowModel> homeFindAll(HomeThreeShowModel model) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.homeFindAll(model);
        /**if (jedis.exists("home_picture")) {
         List<String> home_picture = jedis.lrange("home_picture", 0, -1);
         List<String> title = jedis.lrange("title", 0, -1);
         List<String> backGround = jedis.lrange("backGround", 0, -1);
         for (int i = 0; i < home_picture.size(); i++) {
         RoomModel model = new RoomModel();
         model.setRoomPhoto(home_picture.get(i));
         // model.setName(jedis.lindex("navName", i));
         model.setHomeBackTitle(title.get(i));
         model.setHomeBackGroud(backGround.get(i));
         list.add(model);
         }
         } else {
         list = iRoomDao.homeFindAll(roomModel);
         for (int i = 0; i < list.size(); i++) {
         jedis.rpush("home_picture", list.get(i).getRoomPhoto());
         jedis.rpush("title", list.get(i).getHomeBackTitle());
         jedis.rpush("backGround", list.get(i).getHomeBackGroud());
         }
         }
         return list;*/
    }

    @Override
    public int getNumber(HomeThreeShowModel model) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.getNumber(model);
    }

    //-------------------前端调值👇👇👇👇👇👇👇👇👇👇👇👇----------------------------
//    @Override
//    public List<RoomModel> getRoomModel() {
//        IRoomDao iRoomDao = new RoomImpl();
//        return iRoomDao.getRoomModel();
//    }

    /**
     * 网站首页调取
     *
     * @return
     */
    @Override
    public List<RoomModel> getRoomModelList() {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.getRoomModelList();
    }

    /**
     * 获取指定数量的数据
     *
     * @return
     */
    @Override
    public List<RoomModel> getAppointRoomModel(Map<String,Integer> map) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.getAppointRoomModel(map);
    }

    /**
     * 获取首页的三张图片
     *
     * @return
     */
    @Override
    public List<HomeThreeShowModel> getThree() {
        IRoomDao iRoomDao = new RoomImpl();
        List<HomeThreeShowModel> list = new ArrayList<>();
        Jedis jedis = new Jedis();
//        RoomModel roomModel = new RoomModel();
        if (jedis.exists("home_roomPhoto")) {
            List<String> home_roomPhoto = jedis.lrange("home_roomPhoto", 0, -1);
            List<String> home_backGroundImg = jedis.lrange("home_backGroundImg", 0, -1);
            List<String> home_roomTitle = jedis.lrange("home_roomTitle", 0, -1);
            for (int i = 0; i < home_roomPhoto.size(); i++) {
                //赋值
                HomeThreeShowModel model = new HomeThreeShowModel();
                model.setRoom(home_roomPhoto.get(i));
                model.setBack(home_backGroundImg.get(i));
                model.setTitle(home_roomTitle.get(i));
                list.add(model);
            }
        } else {

            list = iRoomDao.getThree();
            for (int i = 0; i < list.size(); i++) {
                jedis.rpush("home_roomPhoto", list.get(i).getRoom());
                jedis.rpush("home_backGroundImg", list.get(i).getBack());
                jedis.rpush("home_roomTitle", list.get(i).getTitle());
            }
        }
        return list;
    }

    /**
     * 根据用户点击的房间id 获取房间详细信息
     *
     * @param temp
     * @return
     */
    @Override
    public List<RoomModel>find(Integer temp) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.find(temp);
    }

    @Override
    public int getTotal(Integer temp) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.getTotal(temp);
    }

    @Override
    public int homeAdd(HomeThreeShowModel model) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.homeAdd(model);
    }

    @Override
    public int homeEdit(HomeThreeShowModel model) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.homeEdit(model);
    }

    @Override
    public int homeDelete(Integer temp) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.homeDelete(temp);
    }

    @Override
    public HomeThreeShowModel homeFindById(Integer aa) {
        IRoomDao iRoomDao = new RoomImpl();
        return iRoomDao.homeFindById(aa);
    }
}
